package com.olt.dao.user;
import com.olt.domain.user.OltRole;
import com.olt.domain.user.RolePower;
import com.olt.server.dto.SelectDto;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

@SuppressWarnings("MybatisXMapperMethodInspection")
public interface IRoleDao extends JpaRepository<OltRole,Long> {

    OltRole getFirstByRoleName(String name);

    Page<OltRole> findAllByRoleNameContainingOrRoleNameZhContaining(String name, String nameZh, Pageable pageable);


    @Modifying
    @Query(nativeQuery = true, value = "UPDATE Olt_Role SET role_name=?1,role_name_zh=?2 WHERE role_id=?3")
    void updateRole(String roleName,String roleNameZh,Long id);

    OltRole getByRoleId(Long roleId);

    @Query(value = "select r from OltRole r left join UserRole u on r.roleId=u.roleId where u.userId=?1")
    List<OltRole> getRoleNameByUserId(Long userId);


}
